<template>
  <div class="toolbar text-slate-600 text-xs">
    <div class="item">
      <label for="language">语言:</label>
      <select
        name="language"
        id="language"
        :disabled="disabled"
        :value="config.language"
        @change="handleSelectLanguage"
      >
        <option :value="option" :key="option" v-for="option in languages">
          {{ option }}
        </option>
      </select>
    </div>
    <div class="item">
      <label for="theme">主题:</label>
      <select name="theme" id="theme" :disabled="disabled" v-model="config.theme">
        <option :value="option" :key="option" v-for="option in ['default', ...themes]">
          {{ option }}
        </option>
      </select>
    </div>
    <div class="item">
      <label for="disabled">编辑:</label>
      <input type="checkbox" id="disabled" :disabled="disabled" v-model="config.disabled" />
    </div>
    <div class="item">
      <label for="autofocus">自动聚焦:</label>
      <input
        type="checkbox"
        id="autofocus"
        :disabled="disabled"
        v-model="config.autofocus"
      />
    </div>
    <div class="item">
      <label for="indentWithTab">indentWithTab:</label>
      <input
        type="checkbox"
        id="indentWithTab"
        :disabled="disabled"
        v-model="config.indentWithTab"
      />
    </div>
    <div class="item">
      <label for="tabSize">tabSize:</label>
      <Select
        size="small"
        :disabled="disabled"
        v-model.number="config.tabSize"
      >
        <SelectOption :value="option" :key="option" v-for="option in [2, 4, 6, 8]">
          {{ option }}
        </SelectOption>
      </Select>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent, PropType } from 'vue'
  import { Select,SelectOption } from 'ant-design-vue'
  export default defineComponent({
    name: 'Toolbar',
    components: {
      Select,
      SelectOption
    },
    props: {
      disabled: {
        type: Boolean,
        default: false
      },
      config: {
        type: Object,
        required: true
      },
      languages: {
        type: Array as PropType<Array<string>>,
        required: true
      },
      themes: {
        type: Array as PropType<Array<string>>,
        required: true
      }
    },
    methods: {
      handleSelectLanguage(event: any) {
        this.$emit('language', event.target.value)
      }
    }
  })
</script>

<style lang="scss" scoped>
  .toolbar {
    background-color: #fff;
    text-align: left;
    border-bottom: 1px solid rgba(5, 5, 5, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 3rem;
    padding: 0 1em;
  }
</style>
